package io.github.junxworks.junx.stream.pipeline;

import lombok.Getter;
import lombok.Setter;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

@Setter
@Getter
public class ExecFuture {
    private CountDownLatch latch = new CountDownLatch(1);

    private AtomicLong errorCount = new AtomicLong(0);

    private boolean isError = false;

    public void addErrorCount() {
        isError = true;
        errorCount.incrementAndGet();
    }
    public void addErrorCount(long n) {
        isError = true;
        errorCount.addAndGet(n);
    }

    public void await() throws InterruptedException {
        latch.await();
    }

    public void countDown() {
        latch.countDown();
    }

    public boolean isDone() {
        return latch.getCount() == 0;
    }

    public boolean isNotDone() {
        return latch.getCount() > 0;
    }

    public void awaitSeconds(long timeout) throws InterruptedException {
        latch.await(timeout, TimeUnit.SECONDS);
    }

    public void awaitMins(long timeout) throws InterruptedException {
        latch.await(timeout, TimeUnit.MINUTES);
    }
}
